Skip to content

refactor(stack-encrypt)!: make Encrypt and Decrypt Stack Encrypt's own derives - #2016

Open
coderdan wants to merge 18 commits into
fix/encrypt-derived-newtypefrom
feat/stack-encrypt-own-derives
Open

coderdan wants to merge 18 commits into
fix/encrypt-derived-newtypefrom
feat/stack-encrypt-own-derives

Conversation

@coderdan

Copy link
Copy Markdown
Contributor

Summary

#[derive(Encrypt)] and #[derive(Decrypt)] are now Stack Encrypt's own derives. A crate whose only dependency is stack-encrypt can derive both traits, or write them by hand. Before this PR, the user's Cargo.toml also needed vitaminc-aead, and the compile error did not say so.

The vitaminc-aead-derive crate is deleted. vitaminc-aead keeps the traits and has no derives of its own.

Closes #2013. This PR is stacked on #2014. Both change the same derive code.

What a user writes

Before:

stack-encrypt = "…"
vitaminc-aead = "0.10"   # only so that the derive compiles

After, stack-encrypt alone. The derive code is the same:

use stack_encrypt::{Decrypt, Encrypt};

#[derive(Encrypt, Decrypt)]
struct Email(String);

A hand-written impl imports from stack_encrypt:

use stack_encrypt::{plaintext::{depth, Sink}, Scalar};

Changes

  1. The derive code moved into stack-encrypt-derive. Its source, unit tests, and attribute docs moved with git mv, so they keep their history. There is one place to fix a derive bug, and one set of expansion tests.

  2. Generated code names stack_encrypt. It writes ::stack_encrypt::__derive::X. __derive is a hidden module that lists only the 23 items the generated code uses. #[aead(crate = "...")] still overrides the path, for crates in this repository that cannot name stack_encrypt.

  3. New public paths for a hand-written impl:

    • at the crate root: Scalar and FromScalar, beside Encrypt, EncryptRef, Decrypt, and DecodeError;
    • a new stack_encrypt::plaintext module: Sink, SeqSink, MapSink, and the type descriptions such as FixedType;
    • stack_encrypt::plaintext::depth: SCALAR, MAX_DEPTH, and the other depth helpers.

    The whole vitaminc_aead crate is not re-exported.

  4. Compile errors name Stack Encrypt paths, such as stack_encrypt::plaintext::depth::MAX_DEPTH.

  5. A crate that proves it: packages/stack-encrypt-downstream. It is a workspace member that CI builds, with publish = false. Its only dependency is stack-encrypt.

    • It derives both traits for a newtype, a struct, a fieldless enum, and two generic types.
    • It writes Encrypt, Scalar, and FromScalar by hand for one more type.
    • Its tests encrypt and decrypt through keyset.encrypt and encrypt_tree.
    • tests/manifest.rs fails if the crate lists any dependency but stack-encrypt, or names a vitaminc crate.
  6. vitaminc-aead's own derive tests stay where they are. They use stack-encrypt-derive as a dev-dependency, with #[aead(crate = "::vitaminc_aead")]. So mutation testing of vitaminc-aead still runs them.

  7. Every other Cargo workspace drops its patch entry for the deleted crate. None of them used the derives. They are:

    • both Go guests
    • recipher-js, and its test addon
    • EQL, and its generator
    • three fuzz crates
  8. Docs and config: CHANGELOGs, AGENTS.md, SECURITY.md, CODEOWNERS, release-plz.toml, the mutation-testing config, and the path filters of ten workflows.

Breaking changes

  • #[derive(vitaminc_aead::Encrypt)], or importing the derive macros from vitaminc_aead, no longer compiles. Import them from stack_encrypt.
  • #[aead(crate = "...")] now names the path to stack_encrypt. A path to vitaminc_aead still works, because that crate has the same hidden module.
  • The attributes and the stored values do not change.

Verification

Run locally on Rust 1.94.1.

  • Root workspace:

    • fmt, and clippy with -D warnings for all features and for stack-encrypt with no default features
    • tests of stack-encrypt-derive, vitaminc-aead (all features), stack-encrypt (all features, with the compile tests), stack-encrypt-downstream and recipher-frame
    • doctests for the whole workspace
    • vitaminc-aead tests with no features, and with each of jiff, rust_decimal, uuid, and hlist
  • Rustdoc: public and private items, with -D warnings, for the changed crates.

  • Mutation testing (--in-diff): 17 mutants, 14 caught, 3 that do not compile, 0 missed.

  • Supply chain: cargo vet --locked, and cargo deny for vitaminc-aead and recipher-frame.

  • Lockfiles: cargo metadata --locked passes in all 10 workspaces whose lockfile changed.

  • Other workspaces:

    • EQL: eql-bindings with all features, and the encryption tests
    • both Go guests, for wasm32, under their feature sets
    • recipher-js: fmt, clippy, and tests

    These ran before the merge of fix(stack-encrypt): encrypt a derived newtype with keyset.encrypt #2014's latest commits. Those commits changed only messages and docs.

  • Test counts: no test was removed. The 93 derive unit tests are the old crate's 61 plus 32. The derive doctests went from 43 to 29, because the old crate included its attribute docs three times; the 8 distinct examples each run once.

  • Not run: the nightly fuzz builds, the release-only jiff test, and the script tests, because the worktree has no node_modules.

Related

Review notes

Open questions:

  1. Publishing. A published stack-encrypt depends on vitaminc-aead from crates.io, so vitaminc-aead must be published from this repository first. Removing its derive macros is a breaking change. 0.11.0 is the semver-correct version, but the vitaminc crates that depend on it would need new releases too.
  2. Licence. The moved files were MIT-licensed. They keep that licence in src/value/LICENSE-MIT. The crate itself is licensed PolyForm Internal Use. In git, the only authors of these files are CipherStash staff and release bots, so they could be relicensed.
  3. The attribute name stays #[aead(...)]. It does not name vitaminc. It also keeps these attributes apart from the record derives' #[stash(...)]: both have a passthrough key with a different meaning.
  4. A rustc note a user may see. A refused trait bound can print "there are multiple different versions of crate vitaminc_aead in the dependency graph". It comes from vitaminc-aead 0.5.1. That version is a dependency of cts-common. This PR does not cause it.
  5. Each commit builds on its own, except one gap. Between the second and third commits, the other Cargo workspaces still name the deleted crate. The root workspace builds at every commit.

… names

A type can implement `Encrypt` and `Decrypt` by hand instead of deriving
them. Such an impl names the sink traits, the `depth` constants, the types
of a scalar, and the `Scalar` and `FromScalar` traits. `stack-encrypt`
re-exported none of these, so a crate that wrote such an impl had to
depend on `vitaminc-aead` too.

The new `stack_encrypt::plaintext` module re-exports the sink traits and
the scalar types. It also has a `depth` module of its own. That module
adds `MAX_DEPTH` to the depth constants. `Scalar` and `FromScalar` are
re-exported at the crate root, next to `Encrypt`, and `Decrypt`. The
module docs show a complete hand-written `Encrypt` and `FromScalar` impl,
run against the in-memory key source.

The `OpaqueEncode` docs and doctests now import from `stack_encrypt`. The
compile error for a `Scalar` type with the wrong `DEPTH` names
`stack_encrypt::plaintext::depth::SCALAR`. A refused `FromScalar` bound
now prints as `FromScalar`, through the root re-export, so one UI
snapshot changes in that line only.
…pt's derives

`stack_encrypt::Encrypt` and `stack_encrypt::Decrypt` re-exported the
derives of vitaminc-aead-derive. Their code named every item through
`::vitaminc_aead`. Rust resolves that path only in a crate that lists
`vitaminc-aead` as a dependency of its own. So a crate that depended on
`stack-encrypt` alone could not derive either trait. The error did not
say why.

The two derives now live in `stack-encrypt-derive`, in `src/value/`, and
`stack-encrypt` re-exports them. The generated code names every item
through `<crate>::__derive`. `<crate>` is `::stack_encrypt` unless
`#[aead(crate = "...")]` names another path. `vitaminc_aead::__derive` is
a hidden module that lists exactly the items the expansion names, and
`stack_encrypt::__derive` re-exports it. No other part of vitaminc-aead
is re-exported for the derives.

vitaminc-aead-derive is removed rather than kept as a second public
derive. So a derive bug has one place to fix, and one set of expansion
tests. Its source, unit tests, and attribute docs move with their
history. The moved files keep their MIT licence, in `LICENSE-MIT` beside
them. vitaminc-aead loses its derive dependency and its re-export of the
macros. Its own tests and doctests use Stack Encrypt's derive, with
`#[aead(crate = "::vitaminc_aead")]`, since stack-encrypt depends on it.

The attributes keep the name `aead`. That name does not name vitaminc.
It also keeps them apart from the `#[stash(...)]` attributes of the
record derives. So neither family of derives refuses the other's keys.

The wire shape does not change. The UI snapshots change only in line
numbers and in the depth error. That error now names
`stack_encrypt::plaintext::depth::MAX_DEPTH`.

These move with the crate:

- the root workspace member and patch;
- the mise task include, with a rustdoc task for stack-encrypt-derive in
  place of the old crate's;
- the release-plz entry;
- the mutation-testing config, now for the value derives only;
- the workflow path filters and CODEOWNERS;
- the vitaminc-aead supply-chain config.

cargo deny now leaves stack-encrypt-derive out of vitaminc-aead's graph,
as cargo vet's filter already did. The derive's own tests reach the
whole workspace.

BREAKING CHANGE: `vitaminc_aead::Encrypt` and `vitaminc_aead::Decrypt`
are traits only. Import the derives from `stack_encrypt`.
`#[aead(crate = "...")]` now names the path to `stack_encrypt`. A path to
`vitaminc_aead` still works.
…paces

Every Cargo workspace that resolves vitaminc-aead 0.10 patched both
vitaminc-aead and vitaminc-aead-derive to the copies in this repository.
The derive crate is gone, and vitaminc-aead no longer depends on it, so
nothing in these workspaces resolves vitaminc-aead-derive 0.10 any more.
A patch that names a missing path fails every cargo command in the
workspace.

These workspaces now patch vitaminc-aead alone:

- the two Go guests;
- recipher-js, and its test addon;
- EQL, and its timing generator;
- the three fuzz crates.

Each `Cargo.lock` loses the vitaminc-aead-derive 0.10 entry. The 0.5.1
copy that cts-common reaches through vitaminc 0.5.1 still comes from
crates.io. No code in these workspaces used the derives.
…ncrypt alone

Every crate in this repository that derived `Encrypt` or `Decrypt`
already depended on vitaminc-aead. So nothing noticed that the derives
did not compile without it. The new crate is a member of the root
workspace. Its only dependency is `stack-encrypt`, as an application's
would be. `tests-crates.yml` builds and tests it with the rest.

The crate derives both traits for these types:

- a newtype;
- a struct with named fields and a passthrough field;
- a fieldless enum;
- a generic newtype;
- a generic struct.

It also writes `Encrypt`, `Scalar`, and `FromScalar` by hand for one more
type. Its tests send each type through `keyset.encrypt` or
`keyset.encrypt_tree` and back, under the in-memory key source.

`tests/manifest.rs` fails if the manifest names a dependency other than
`stack-encrypt`. It also fails if any table names a vitaminc crate. Two
trybuild cases pin what a user reads when a derive is refused. The trait
bounds print as `stack_encrypt` paths. The depth error names
`stack_encrypt::plaintext::depth::MAX_DEPTH`.

The crate implements `Zeroize` by hand, through `stack_encrypt`'s
re-export of the trait, so that it needs no zeroize dependency either.
It is `publish = false`, with `release = false` in release-plz.toml. The
live jobs of tests.yml skip a change that touches only this crate.
The stack-encrypt CHANGELOG has two new entries:

- Under Fixed: the derives now compile in a crate that depends only on
  stack-encrypt. The entry says what stays the same, what
  `crate = "..."` now names, and how to migrate.
- Under Added: the `plaintext` module, and the `Scalar` and `FromScalar`
  re-exports, for a hand-written impl.

Two entries of the same release named `vitaminc_aead::plaintext::depth`
and "Vitamin C's `Scalar`". They now name the stack-encrypt paths.

The vitaminc-aead CHANGELOG lists two changes under Breaking. The crate
has no derives of its own, and the entry says how to import them instead.
The hidden `plaintext::__private` module is replaced by `__derive`.

AGENTS.md's repository layout and SECURITY.md's package list name the
two AEAD crates that remain. They say where the value derives went, and
describe stack-encrypt-downstream.
…derives

Brings in the latest review fixes of the base branch. Conflicts, and how
they are resolved:

- The derive's `encrypt.rs` moved to
  `packages/stack-encrypt-derive/src/value/encrypt.rs` here. The base
  branch decides once whether a type has a fixed depth. Its logic is kept
  as it is, with the generated paths renamed to `#aead::...` as in the
  rest of the moved file.
- `vitaminc-aead-derive/src/lib.rs` is deleted here. Its new paragraph,
  that `#[derive(Zeroize)]` does not wipe a fieldless enum, moves to
  `stack-encrypt-derive/docs/value-derives.md`, with its doctest importing
  `stack_encrypt::Encrypt`.
- `scalar.rs` keeps the base branch's new text and its wording of the
  `DEPTH` error, with the `stack_encrypt::plaintext::depth::SCALAR` path.
- The stack-encrypt CHANGELOG keeps the base branch's entry, names
  `stack_encrypt::plaintext::depth`, and no longer says that a crate
  needs vitaminc-aead to use the derive.
- The vitaminc-aead CHANGELOG has one Breaking section with the entries
  of both branches.
@changeset-bot

changeset-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 220b79a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5ffbaf56-2efb-4680-94ea-a108a4f35d89

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth, stack-encrypt, stack-encrypt-jsonpath, stack-encrypt-derive, vitaminc-aead, recipher-frame)

caught missed unviable timeout
16 0 3 0

Every mutant in the changed lines was caught by a test.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review at medium effort. Five findings: one pre-existing problem that this PR widens, and four nits. I checked each one against the branch. For the first, I also compared the registry copy of vitaminc-aead 0.10.0 with the copy in this repository.

// The code that `#[derive(Encrypt)]` and `#[derive(Decrypt)]` write names
// each item through `::stack_encrypt::__derive`. Not an API.
#[doc(hidden)]
pub use vitaminc_aead::__derive;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing, made one step wider: a published stack-encrypt cannot build against vitaminc-aead 0.10.0 from crates.io.

This line re-exports vitaminc_aead::__derive, which exists only in the copy in this repository. That copy is still at version 0.10.0, and the root Cargo.toml asks for 0.10.0 through a [patch]. Once cargo publish strips the path, the registry's 0.10.0 has no __derive, so the build fails with E0432.

This is not new. stack-encrypt on next already uses OwnedFrame and ValueKind, which crates.io's 0.10.0 does not have (I checked the registry source). What is new: this PR also removes vitaminc-aead's public Encrypt and Decrypt derives under the same version number, which is a breaking change in what looks like a patch release.

Fix: release planning, not code. vitaminc-aead needs a new version that marks the break (0.11.0), published from this repository before stack-encrypt. This is open question 1 in the description, for the maintainer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is for the maintainer, not a code change in this PR. It is open question 1 in the description: vitaminc-aead needs a new version that marks the break, published from this repository before stack-encrypt. The fixes for the other four findings are in progress.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major The CHANGELOG makes the same claim: packages/stack-encrypt/CHANGELOG.md:1801 says "A path to vitaminc_aead still works" for #[aead(crate = …)]. That holds only against the patched in-tree copy, because the derive appends __derive and crates.io 0.10.0 has none. stack-encrypt 0.3.0 is not on crates.io and eql-pipeline-armed.mjs crates reports armed, so release-plz would try the publish once this reaches main. stack-encrypt-jsonpath and stack-encrypt-derive 0.3.0 do not depend on vitaminc-aead, so they could publish before stack-encrypt fails verification (not reproduced). A guard would catch it before release: run cargo publish --dry-run -p stack-encrypt on PRs, or make release-crates refuse while vitaminc-aead is release = false. Also qualify the CHANGELOG line.

Source: code-review · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that this needs a guard, and it is already true on next, before this PR.

On next, release-plz.toml publishes stack-encrypt 0.3.0, and crates.io has only 0.1.0 and 0.2.0. stack-encrypt on next already uses OwnedFrame and ValueKind, which crates.io's vitaminc-aead 0.10.0 does not have. So a release from main would already fail at stack-encrypt, possibly after stack-encrypt-jsonpath and stack-encrypt-derive have published. This PR adds __derive to the same list.

Whether to add a guard, and which one, is for the maintainer. I've raised it. The CHANGELOG line is being qualified in this PR.

Comment thread supply-chain/vitaminc-aead/filter-graph Outdated
@@ -1 +1 @@
exclude(all(is_workspace_member(true),not(any(name(vitaminc-aead),name(recipher-frame),name(vitaminc-aead-derive)))))
exclude(all(is_workspace_member(true),not(any(name(vitaminc-aead),name(recipher-frame)))))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The derive code is no longer covered by cargo vet and cargo deny.

Before this PR, vitaminc-aead-derive and its dependencies (syn, quote, proc-macro2) were in this filter's checked set. The same code is now in stack-encrypt-derive, which this filter and deny.toml (exclude = ["stack-encrypt-derive"]) both leave out. supply-chain-vitaminc-aead.yml also no longer starts when that code changes, because its path filter does not list packages/stack-encrypt-derive/**.

So a change to the code that writes every derived Encrypt impl, or a bump of its syn dependency, is no longer vetted.

Fix: keep stack-encrypt-derive in the checked graph and in the workflow's path filter, or vet it in whichever workflow covers stack-encrypt's graph. The exclude was added because the derive's dev-dependencies pull in the whole workspace; excluding its dev-dependencies alone may be enough.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 01acb74, with a comment correction in 6e5cda5.

  • The workflow now starts when packages/stack-encrypt-derive/** changes.
  • cargo deny checks the derive as the root of its own graph, without its dev-dependencies (--exclude-dev). That graph is 18 crates: syn, quote, proc-macro2, stack-encrypt-jsonpath and their dependencies. vitaminc-aead's and recipher-frame's checks are unchanged.
  • cargo vet requires the derive's normal dependencies at safe-to-deploy, as it did for vitaminc-aead-derive. It puts no requirement on the derive's dev-dependencies, which reach the whole workspace.

Three additions for the maintainer to review:

  • Two exemptions, for thiserror 1.0.69 and thiserror-impl 1.0.69 at safe-to-deploy, the same as the existing 2.0.18 entries. They come in through stack-encrypt-jsonpath, and no imported registry audits them. No audits were written.
  • Two licence exceptions, for stack-encrypt-derive and stack-encrypt-jsonpath only, by name. Their LICENSE file is the PolyForm Internal Use License, which cargo-deny 0.20.2 reads as PolyForm-Small-Business-1.0.0. I confirmed that with cargo deny list.
  • A policy on stack-encrypt-jsonpath that does not require miette. miette comes only with jsonpath's diagnostics feature, which the derive does not turn on.

I ran the workflow's own commands with the pinned versions: deny passes for all three roots, and vet reports "Vetting Succeeded".

let message = format!(
"`{name}` nests deeper than `MAX_DEPTH` levels, so the encrypting sink would refuse \
its fully populated values"
"`{name}` nests deeper than `stack_encrypt::plaintext::depth::MAX_DEPTH` levels. Stack \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the too-deep error always names stack_encrypt::plaintext::depth::MAX_DEPTH, even with #[aead(crate = "...")].

Every other path in the expansion follows the crate attribute, but this message is a fixed string. In vitaminc-aead's own tests and docs, which use #[aead(crate = "::vitaminc_aead")], the error names a path that does not resolve there.

Fix: build the path from the attribute, or name the limit without a crate path ("more than MAX_DEPTH levels").

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 59b2128. The message is now built from the crate path that the rest of the expansion uses:

  • default: "TooDeep nests deeper than stack_encrypt::plaintext::depth::MAX_DEPTH levels. …"
  • with crate = "::vitaminc_aead": "TooDeep nests deeper than vitaminc_aead::plaintext::depth::MAX_DEPTH levels. …"

vitaminc_aead::plaintext::depth now re-exports MAX_DEPTH, so the second path resolves. A new expansion test failed against the old fixed string and passes now.

let tables = tables();
let dependencies = tables
.iter()
.find(|(name, _)| name == "dependencies")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the guard reads only the table named exactly [dependencies].

A dependency added as [dependencies.serde], under [target.'cfg(unix)'.dependencies], or under [build-dependencies] is never compared, and the_only_dependency_is_stack_encrypt still passes. The crate would then no longer prove what its docs say.

Fix: treat every dependency table as a dependency table (any table whose name is, or ends in, dependencies, except dev-dependencies), and fail when one lists anything but stack-encrypt. Add a test case for each form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0f566a1. The guard now parses the manifest with the toml crate, which trybuild already brings into the lockfile. It reads every dependency table: [dependencies], [build-dependencies] and [dev-dependencies], at the top level and under every [target.<cfg>], including sub-tables and dotted keys. Only a dev-dependency table may list anything but stack-encrypt, and no table may name a vitaminc crate, renamed or not.

13 new unit tests cover each form, so the guard itself is tested.

@@ -0,0 +1,12 @@
//! What a user of `stack-encrypt` reads when a derive is refused. The
//! errors name `stack_encrypt` paths, since this crate has no other
//! dependency. Re-record with `TRYBUILD=overwrite cargo test -p

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the snapshot can match only one feature set, and the re-record command picks the wrong one.

field_type_not_encryptable.stderr records rustc's list of FromScalar implementors, which changes with features. CI runs cargo nextest run --workspace --all-features, and feature unification adds implementors such as Decimal. The command in this comment re-records without --all-features. stack-encrypt's own tests/ui.rs warns about this and limits its test with required-features.

Fix: record and run under --all-features only (a required-features entry, and the flag in this comment), or choose a refused type whose error lists no implementors.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked, and the snapshot already matches every feature set. trybuild builds the compile cases as a separate project, with only this crate's own features and dev-dependencies. Workspace feature unification does not reach it, and this crate has no features. The test passes with and without --all-features, and with CI's --workspace --all-features.

The suggested required-features pattern made it worse: adding a feature to this crate changed the implementor list under --all-features. So a685a32 instead explains this in tests/ui.rs and Cargo.toml, and adds a manifest test, the_crate_has_no_features, that keeps the condition this depends on.

The code that writes every derived `Encrypt` and `Decrypt` impl moved from
vitaminc-aead-derive to stack-encrypt-derive. The supply-chain checks left
the new crate out, so a change to it, or a bump of its syn, was no longer
vetted. The workflow also did not start when the derive changed.

The derive's dev-dependencies include stack-encrypt, and stack-encrypt
reaches the rest of the workspace. So each tool now leaves out those dev-dependencies
alone, and keeps the derive's normal dependencies:

- cargo deny checks the derive as the root of its own graph, with
  `--exclude-dev`. The other two crates' checks leave the derive out with
  `--exclude`. A `[graph] exclude` entry cannot do this, because cargo
  deny cannot use an excluded crate as a root.
- cargo vet keeps the derive and stack-encrypt-jsonpath in the filter.
  The derive's policy is `safe-to-deploy`, with `dev-criteria = []`.
- stack-encrypt-jsonpath's policy asks nothing of miette. miette comes
  only with the `diagnostics` feature. The derive does not turn it on.

The derive's graph brings in thiserror 1.0.69 and thiserror-impl 1.0.69,
through stack-encrypt-jsonpath. No imported registry audits them, so
they are exemptions at `safe-to-deploy`, as thiserror 2.0.18 is. The
reviewer decides whether an audit should replace them. The licence
check allows the PolyForm Small Business licence for the two
first-party crates only.
The too-deep compile error named
`stack_encrypt::plaintext::depth::MAX_DEPTH` as fixed text. Every other
path in the expansion follows `#[aead(crate = "...")]`. A type derived
with `crate = "::vitaminc_aead"`, as vitaminc-aead's tests and docs do,
was told about a path that does not resolve there.

The message now builds the path from the crate path. vitaminc-aead
re-exports `MAX_DEPTH` from `plaintext::depth`, as stack-encrypt does, so
the path resolves under both crates. An expansion test checks the message
for the default path and for `::vitaminc_aead`. vitaminc-aead's
`sink_too_deep` snapshot now names `vitaminc_aead::plaintext::depth::MAX_DEPTH`.
The manifest guard compared only the table named `[dependencies]`. A
dependency written as `[dependencies.serde]`, or listed under
`[target.'cfg(unix)'.dependencies]` or `[build-dependencies]`, was never
read. The guard still passed, and the crate no longer showed what its
docs say.

The guard now parses the manifest with the `toml` crate, as a new
dev-dependency. trybuild already brings `toml` 1.1.8 into the lockfile.
Parsing reads every form Cargo accepts, including dotted keys under a
target. A table other than a dev-dependency table can list only
stack-encrypt, at the top level or under a target. No table names a
vitaminc crate, under its own name or through `package`. Unit tests feed
the checks a manifest for each form.
…ture set

rustc lists a trait's other implementors in the errors that
`field_type_not_encryptable.stderr` records. A stack-encrypt feature such
as `dynamic` adds implementors. So the recording looked as if it could
match only one feature set, and as if the re-record command picked the
wrong one.

It matches every feature set. trybuild builds the ui cases as a separate
project, from this crate's dev-dependencies and features.
This crate has no features, so CI's `--workspace --all-features` run
records the same errors as a plain `cargo test`. Both pass with the
committed recording.

Limiting the test with `required-features`, as stack-encrypt's own ui
test does, would need a feature here that turns on `stack-encrypt/dynamic`.
That feature would add `&Frame<'_>` and `&Lent<'_, T>` to the lists, and
so make the recording depend on features after all.

The ui test's docs now say why the recording matches every feature set.
A manifest test fails if a `[features]` table is added to this crate.
The comment above the two licence exceptions said the crates are under a PolyForm Small Business licence. Their LICENSE file is the PolyForm Internal Use License. cargo-deny reads that text as PolyForm-Small-Business-1.0.0, so the exception has to name that identifier. The comment now says so.
@coderdan
coderdan marked this pull request as ready for review November 28, 2026 11:34
@coderdan
coderdan requested a review from a team as a code owner November 28, 2026 11:34

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed 6e5cda5 · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review agent · claude-opus-5-5; rust-security agent · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check

Findings (5): 2 major, 3 minor — 3 inline, 1 below, 1 in reply.

  • AGENTS.md:817 (outside diff) minor Two sentences still say there are three AEAD crates: AGENTS.md:817-818 ("for the three AEAD crates kani.yml, …") and AGENTS.md:878 ("All three #[deny(unsafe_code)]"), and so does the root Cargo.toml:5 comment. Only vitaminc-aead and recipher-frame remain, so change "three" to "two" at all three sites.

    Source: mattpocock-skills:code-review agent · claude-opus-5-5


Generated by Claude Code

Comment thread AGENTS.md Outdated
@@ -769,7 +768,7 @@ reaches a published crate only once the copies are published from here,
which the plan schedules before the next `stack-encrypt` release.

- **Three Cargo workspaces, not one.** The root workspace (the seven stack-*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major This PR adds packages/stack-encrypt-downstream to the root workspace members (Cargo.toml:17), so there are now eight stack-* crates, not seven. The Repository Layout bullet at line 93 also leaves it out of its opening path list and still says "and one added here". Change "seven" to "eight" here, and add the crate to line 93's list with "two added here".

Source: mattpocock-skills:code-review agent · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d2274a9. The Repository Layout bullet lists packages/stack-encrypt-downstream and says "two added here", and "Working on the Rust crates" says eight stack-* crates. SECURITY.md now says the crate is an unpublished test crate, as it does for eql-encryption-tests.

@@ -20,7 +20,6 @@ on:
- packages/stack-guest-abi/**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor packages/stack-encrypt-downstream/** is missing from both path lists (the pull_request list here and the push list at line 42), though tests-crates.yml lists it. A PR that changes only packages/stack-encrypt-downstream/tests/manifest.rs to stop using toml leaves an unused dev-dependency, and udeps never starts. Add the path to both lists.

Source: code-review · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4c4a3d3. packages/stack-encrypt-downstream/** is in both the pull_request and push path lists, and the two lists match. No other workflow needs it: the others list the derive because their builds depend on stack-encrypt, and nothing depends on the downstream crate.

@@ -0,0 +1,113 @@
//! Types of an application that depends on `stack-encrypt` and nothing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor This crate has none of the security lint block its stack-* siblings carry (stack-encrypt/src/lib.rs:3-16), and no [lints] table covers it. A dbg!(&self.cents) or core::mem::forget in impl Encrypt for Price passes CI's clippy -D warnings, because dbg_macro and mem_forget are restriction lints. Copy the block here, with the same allows for unwrap/expect in tests/.

Source: rust-security agent · claude-opus-5-5


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1c29cbd. The crate has the same security lint block as stack-encrypt, with the same allows for tests. I checked that it works: a dbg! and a mem::forget added for a moment both failed clippy.

stack-encrypt-downstream is a member of the root Cargo workspace, so the
counts in AGENTS.md were one short. The Repository Layout bullet now
lists the crate in its opening paths and says two crates were added here.
The workspace note now says eight stack-* crates.

SECURITY.md lists the unpublished test harness `eql-encryption-tests`
and says that it adds no published package. stack-encrypt-downstream is
also an unpublished test crate, so SECURITY.md now says the same of it.
The AEAD crates moved from vitaminc are now vitaminc-aead and
recipher-frame. The derive crate that came with them is gone. Its code
is in stack-encrypt-derive. Two sentences in AGENTS.md and the comment
above the root workspace members still counted three. The AGENTS.md
sentence about `#![deny(unsafe_code)]` is still true of both crates.
cargo udeps runs over the whole root workspace, and stack-encrypt-downstream
is a member. But neither path list named the crate. A change that stops
using one of its dev-dependencies, such as `toml`, did not start the job.
Both lists now name it, as tests-crates.yml does.

The other workflows that list stack-encrypt-derive do so because their
builds depend on stack-encrypt, or because they check named crates.
Nothing depends on stack-encrypt-downstream, so they do not list it.
The other stack-* crates warn on `dbg!`, `mem::forget`, printing,
`unwrap`, `expect`, and `panic!`. Those crates also deny unsafe code.
CI's clippy turns each warning into an error.

The downstream crate had none of these lints. Clippy does not run most of
them by default, because they are restriction lints. So a
`dbg!(&self.cents)` in the hand-written `Encrypt` for `Price` passed CI.

The crate now carries the same block as stack-encrypt, with the same
allowances for unit tests. Nothing in the crate breaks the lints.
The CHANGELOG said that `#[aead(crate = "...")]` still works with a path
to `vitaminc_aead`. The derives' code names `<crate>::__derive`. Only the
`vitaminc-aead` source in this repository has that module. crates.io's
0.10.0 does not. So the line was true only inside this repository, and
the CHANGELOG now says so.

The entry for the too-deep error also says that its path starts at the
`crate` path, when a type names one.
@coderdan

Copy link
Copy Markdown
Contributor Author

The finding outside the diff is fixed in afdfcff. AGENTS.md now says two AEAD crates in both places, and "Both" deny unsafe_code, which I checked for vitaminc-aead and recipher-frame. The root Cargo.toml comment says the same. The CHANGELOG line about a vitaminc_aead crate path is qualified in be75de1.

Brings in #2014 and, through it, next with #2011.

Conflicts:

- stack-encrypt's lib.rs: this branch re-exports `FromScalar` and
  `Scalar`, and #2011 re-exports `ScalarTarget`. The merge re-exports
  all three.
- stack-encrypt's CHANGELOG: both sides added an entry at the top of
  Added. The merge keeps both entries.
- owned_collection_elements.stderr: the merge takes the snapshot of
  #2014. Recording it again with TRYBUILD=overwrite gave the same file.

#2011 added tests and a doc example to vitaminc-aead that use the
derives from vitaminc_aead. On this branch vitaminc-aead has no derives.
So these now use stack_encrypt_derive with
`#[aead(crate = "::vitaminc_aead")]`, as the other vitaminc-aead tests
do:

- tests/scalar_target.rs
- four compile-fail tests in tests/ui/scalar_target/
- the example on `ScalarTarget` in typed.rs

The four snapshots of those compile-fail tests change only in their line
numbers. Two doc comments in typed.rs now say "Stack Encrypt's
`#[derive(Decrypt)]`", as the rest of the file does.
The merge of #2014 added packages/mn-meta.err and packages/eql/tests/timing/mn-meta.err. Both are empty logs from a local lockfile check, and are not part of the change.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants